package com.frogs.ucenter.v1.request;

import javax.servlet.http.HttpServletRequest;

import com.frogs.framework.util.StringUtil;
import com.frogs.framework.web.HttpRequestInfo;
import com.frogs.system.util.ApiUrlParamEnum;
import com.frogs.system.util.ApplicablePlatformEnum;
import com.frogs.system.web.api.request.Request;
import com.frogs.system.web.exception.RequestIllegalException;

public class SmsCheckRequest extends Request {
	
	/**
	 * 验证号码
	 */
	private String phoneNumber;
	/**
	 * 验证码
	 */
	private String verificationCode;
	/**
	 * 平台类型
	 */
	private int applicablePlatformId;
	
	private int operation;
	
	public String getPhoneNumber() {
		return phoneNumber;
	}

	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}

	public String getVerificationCode() {
		return verificationCode;
	}

	public void setVerificationCode(String verificationCode) {
		this.verificationCode = verificationCode;
	}

	public int getApplicablePlatformId() {
		return applicablePlatformId;
	}

	public void setApplicablePlatformId(int applicablePlatformId) {
		this.applicablePlatformId = applicablePlatformId;
	}

	public int getOperation() {
		return operation;
	}

	public void setOperation(int operation) {
		this.operation = operation;
	}

	/** */
	public SmsCheckRequest() {
	}
	
	@Override
	public void parse(HttpServletRequest request) {
		HttpRequestInfo requestInfo = new HttpRequestInfo(request);
		
	
		this.phoneNumber = requestInfo.getParameter(ApiUrlParamEnum.phoneNumber.getParamName());
		this.verificationCode = requestInfo.getParameter(ApiUrlParamEnum.verificationCode.getParamName());
		this.applicablePlatformId = requestInfo.getIntParameter(ApiUrlParamEnum.applicablePlatformId.getParamName(), ApplicablePlatformEnum.ALL.getId());
		if (requestInfo.getIntParameter(ApiUrlParamEnum.sendType.getParamName(), 0) > 0) {
			this.applicablePlatformId = requestInfo.getIntParameter(ApiUrlParamEnum.sendType.getParamName(), 0);
		}
		this.operation = requestInfo.getIntParameter(ApiUrlParamEnum.operation.getParamName(), 0);
		if ( !StringUtil.isMobilePhone(phoneNumber) ) {
			throw new RequestIllegalException("error phoneNumber: " + phoneNumber);
		}
		if ( StringUtil.isEmpty(verificationCode)) {
			throw new RequestIllegalException("error verificationCode: " + verificationCode);
		}
		if ( applicablePlatformId<=0 ) {
			throw new RequestIllegalException("error applicablePlatformId: " + applicablePlatformId);
		}
	}
	
	
}
